#variables 
# ref: https://www.delftstack.com/howto/powershell/command-line-arguments-in-powershell/
param(
	[String]$msg = "update",
    [Switch]$build = $true
)

$git_repo = pwd | Split-Path -LeafBase

#Write-Output ($msg + ", " + $git_repo)
#$msg = if ($2 -lt 0) { 0 } else { $b }
 
$gitee="https://gitee.com/hwaust/"
$url="http://121.199.10.158:8107/ebooks/"


Write-Output "本代码主要包括三大功能："
Write-Output "1. 提交版本 git commit"
Write-Output "2. 代码上传 git push"
Write-Output "3. 远程编译 git pull & gitbook build"

# 更新并上传代码
git add .
git commit -m "$msg"
git push

if($build){
# 上传
Write-Output "updating : $gitee$git_repo"
Write-Output "visit url: $url$git_repo/_book/"
ssh ali "cd /root/myweb/ROOT/ebooks/$git_repo; pwd; ./build.sh"
}
